iOS8和BTLE | CBCentralManager无法找到外围设备

 DilWilling 发布于 2022-12-27 10:44

我有一个使用BTLE连接到设备(arduino)的iOS应用程序.我的iPad iOS 7上的一切正常.升级到iOS 8后,CBCentralManager找不到任何外围设备.

- (void)startScanningForSupportedUUIDs
{
   [self.centralManager scanForPeripheralsWithServices:nil options:nil];

}

我不知道会出现什么问题.

1 个回答
  • 我有解决方案,出于某种原因,在iOS 8中实例化你的CBManager后有一些延迟.您需要在CBCentralManager启用时开始扫描,在此方法中:

    -(void)centralManagerDidUpdateState:(CBCentralManager *)central{
    switch (central.state) {
        case CBCentralManagerStatePoweredOff:
            NSLog(@"CoreBluetooth BLE hardware is powered off");
            break;
        case CBCentralManagerStatePoweredOn:
        {
            NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
            NSArray         *uuidArray  = [NSArray arrayWithObjects:[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID], nil];
            NSDictionary    *options    = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
            [centralManager scanForPeripheralsWithServices:uuidArray options:options];
        }
            break;
        case CBCentralManagerStateResetting:
            NSLog(@"CoreBluetooth BLE hardware is resetting");
            break;
        case CBCentralManagerStateUnauthorized:
            NSLog(@"CoreBluetooth BLE state is unauthorized");
            break;
        case CBCentralManagerStateUnknown:
            NSLog(@"CoreBluetooth BLE state is unknown");
            break;
        case CBCentralManagerStateUnsupported:
            NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
            break;
        default:
            break;
    }
    

    2022-12-27 10:46 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有